import pytest
import requests
import allure
"""
pytest <py文件> --alluredir=allure   # 生成allure  数据
allure generate ./allure/ -o ./reports --clean  #  生成allure报告到reports文件夹里
"""
"""
token关联有很多种方式
"""
"""
class TestCrmeb:
    base_url = "http://8.140.193.160:8899"
    @staticmethod
    def login():
        response = requests.post(url="http://8.140.193.160:8899/adminapi/login",
                                 json={"account": "admin", "pwd": "920509", "imgcode": "a"})
        token = response.json()['data']['token']
        token = "Bearer " + token
        return token
    @allure.story("用户分组")
    def test_user_group(self):
        response = requests.post(self.base_url+"/adminapi/user/user_group/save.html",json={"group_name":"测试一下你就知道123"},headers={"Authori-zation":str(self.login())})
        assert response.json()['msg'] == "提交成功！"
"""
class TestCrmeb:
    base_url = "http://8.140.193.160:8899"
    @pytest.fixture(scope='class',autouse=True)
    def login(self):
        response = requests.post(url="http://8.140.193.160:8899/adminapi/login",
                                 json={"account": "admin", "pwd": "920509", "imgcode": "a"})
        token = response.json()['data']['token']
        with open("token.txt",'w',encoding='utf-8') as f:
            f.write("Bearer " + token)
    @allure.story("用户分组")
    def test_user_group(self):
        with open('token.txt','r',encoding='utf-8') as f:
            token = f.read()
        response = requests.post(self.base_url+"/adminapi/user/user_group/save.html",json={"group_name":"测试一下123"},
                                 headers={"Authori-zation":str(token)})
        assert response.json()['msg'] == "提交成功！"


